package cn.sdormitory.school.dao;

import cn.sdormitory.school.entity.SchoolPatrolHandle;
import cn.sdormitory.school.vo.PatrolHandleQueryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface SchoolPatrolHandleDao extends BaseMapper<SchoolPatrolHandle> {

    /**
     * 查询待处理数据
     * @param chargeTeacherId
     * @return
     */
    List<SchoolPatrolHandle> findToDoListByTeacherId(Long chargeTeacherId);

    /**
     * 查询待处理数据数量
     * @param chargeTeacherId
     * @return
     */
    Integer findToDoListCountByTeacherId(Long chargeTeacherId);

    /**
     * 根据巡查记录id查询
     * @param patrolId
     * @return
     */
    SchoolPatrolHandle findByPatrolId(Long patrolId);

    /**
     * 统计数量
     * @param vo
     * @return
     */
    int findListCount(@Param("vo") PatrolHandleQueryVo vo);

    /**
     * 分页查询
     * @param startNum
     * @param pageSize
     * @param vo
     * @return
     */
    List<SchoolPatrolHandle> findPageList(@Param("startNum")int startNum, @Param("pageSize")int pageSize,
                                           @Param("vo") PatrolHandleQueryVo vo);

    /**
     * 查询昨天未处理的数据
     * @return
     */
    List<SchoolPatrolHandle> findNoHandleYesterdayData();

    /**
     * 根据日期查询值班处理数据
     * @param startDate
     * @param endDate
     * @return
     */
//    @Select("SELECT * FROM t_school_patrol_handle WHERE date_format(create_date,'%Y-%m') = date_format(now(),'%Y-%m') ORDER BY create_date ASC")
//    @Select("SELECT * FROM t_school_patrol_handle WHERE create_date BETWEEN #{startDate} AND #{endDate}")
    List<SchoolPatrolHandle> findByDate(@Param("startDate")String startDate,
                                        @Param("endDate")String endDate,
                                        @Param("patrolType")String patrolType);

    /**
     * 查询发送失败短信
     */
    @Select("SELECT * FROM t_school_patrol_handle WHERE sms_status = '1'")
    List<SchoolPatrolHandle> findDutyFailedSms();
}
